﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;

namespace UI.Forms
{
    public partial class openRQ_select : DevExpress.XtraEditors.XtraForm
    {
        public delegate void DoAction(SVC.client.CardOpenRQ_M m,BindingList<SVC.client.CardOpenRQ_D> ds);//如果有参数的话，定义参数 
        public DoAction FatherRefresh;
        private Guid? clientid=null;
        BindingList<SVC.client.CardOpenRQ_M> ms = new BindingList<SVC.client.CardOpenRQ_M>();

        public openRQ_select(Guid _clientid)
        {
            InitializeComponent();
            clientid = _clientid;
        }

        private void gridView1_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e)
        {
            if (gridView1.FocusedRowHandle < 0) return;
            SVC.client.CardOpenRQ_M m = gridView1.GetRow(gridView1.FocusedRowHandle) as SVC.client.CardOpenRQ_M;
            if (m == null) return;


            gridControl2.DataSource = my.bw.CardOpenRQ_D_Bypid_Get(m.pid, my.ACID);
            gridView2.BestFitColumns();
        }

        private void openRQ_select_Load(object sender, EventArgs e)
        {
            if (clientid==null)
	        {
		         Comm.ShowAlert("请选择一个客户！");return;
	        }
            ms = my.bw.CardOpenRQ_M_ByClientID_Get(clientid,0, my.ACID);
            gridControl1.DataSource = ms;
            gridView1.BestFitColumns();
            rlue_ComboID.DataSource = my.bw.View_Combo_lite_List("", my.ACID);
            rlue_ComboID.DisplayMember = "ComboName";
            rlue_ComboID.ValueMember = "ComboID";
        }

        private void btn_OK_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (gridView1.GetRow(gridView1.FocusedRowHandle)!=null)
            {
                 SVC.client.CardOpenRQ_M m=gridView1.GetRow(gridView1.FocusedRowHandle) as SVC.client.CardOpenRQ_M;
                 BindingList<SVC.client.CardOpenRQ_D> ds = gridView2.DataSource as BindingList<SVC.client.CardOpenRQ_D>;
                 FatherRefresh(m, ds);
                 this.Close();
            }
            else
            {
                Comm.ShowAlert("请选择一个单据！");
            }

        }
    }
}